package ch.zarzu.champions.builder;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ErrorLog {
    /**
     * logs error messages
     */
    public static void v(String preamble, Exception e) {
        DateFormat dateFormat = new SimpleDateFormat("MM.dd.yyyy HH:mm:ss");
        Date date = new Date();
        String path = App.getWriteableDirectory();
        try {
            FileWriter file_writer = new FileWriter(path + "error.txt", true);
            PrintWriter print_writer = new PrintWriter(file_writer);
            print_writer.println(dateFormat.format(date) + " -- " + preamble);
            e.printStackTrace(print_writer);
            print_writer.println();
            print_writer.println();
            
            file_writer.close();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

}
